07. Quantifying State

Quantifying State

Different Motion Models

Constant Velocity

In the first movement example, you saw that if we assumed our car was moving at a constant speed, 50 m/s, we came up with one prediction for it’s new state: at the 150 m mark, with no change in velocity.

```python

Constant velocity case

initial variables

x = 0
velocity = 50
initial_state = [x, velocity]

predicted state (after three seconds)

this state has a new value for x, but the same velocity as in the initial state

dt = 3
new_x = x + velocity*dt
predicted_state = [new_x, velocity] # predicted_state = [150, 50]
```

For this constant velocity model, we had:

  • initial state = [0, 50]
  • predicted state (after 3 seconds) = [150, 50]

Constant Acceleration

But in the second case, we said that the car was slowing down at a rate of 20 m/s^2 and, after 3 seconds had elapsed, we ended up with a different estimate for its state.

To solve this localization problem, we had to use a different motion model and we had to include a new value in our state: the acceleration of the car.

The motion model was for constant acceleration:

  • distance = velocity*dt + 0.5*acceleration*dt^2 and
  • velocity = acceleration*dt

The state includes acceleration in this model and looks like this: [x, velocity, acc].

# Constant acceleration, changing velocity

# initial variables
x = 0
velocity = 50
acc = -20

initial_state = [x, velocity, acc]

# predicted state after three seconds have elapsed
# this state has a new value for x, and a new value for velocity (but the acceleration stays the same)
dt = 3

new_x = x + velocity*dt + 0.5*acc*dt**2
new_vel = velocity + acc*dt

predicted_state = [new_x, new_vel, acc]  # predicted_state = [60, -10, -20]

For this constant acceleration model, we had:

  • initial state = [0, 50, -20]
  • predicted state (after 3 seconds) = [60, -10, -20]

As you can see, our state and our state estimates vary based on the motion model we used and how we assumed the car was moving!

How Many State Variables?

In fact, how many variables our state requires, depends on what motion model we are using.

For a constant velocity model, x and velocity will suffice.

But for a constant acceleration model, you'll also need our acceleration:acc.

But these are all just models.

The Takeaway

For our state, we always choose the smallest representation (the smallest number of variables) that will work for our model.

Reflect

QUESTION:

What are some applications or challenges you can think of, in which the color of a car would be an important state variable?

ANSWER:

You can imagine, if you are a quality assurance engineer, you have to make sure the color of a car is correct before shipping. Another example would be for marketing; you have to make sure that the color of the car matches the logo of the brand or sports team you are trying to match. In these cases, color is very important and would be a valuable state variable!